import axios from "axios";
import "./App.css";
import React from "react";

class App extends React.Component {
  constructor() {
    super();
    //react定义数据
    this.state = {
      username: "",
      http1: "https://sync.minepi.com/node-selection-stats?uuid=",
      ip: "",
    };
  }

  inputChange = (event) => {
    let val = this.refs.username.value;
    this.setState({
      username: val,
    });
  };
  //设置获取数据框内容
  inputip = (event) => {
    let val = this.refs.ip.value;
    this.setState({
      ip: val,
    });
  };

  //ip地址查询
  getInput = () => {
    const url = ":31401";
    const http = "http://";
    const uuid = this.state.ip;
    axios
      .get(http + uuid + url)
      .then((res) => {
        console.log({ res });
        const numube = res.data.core_latest_ledger;
        console.log(numube);
        alert("你输入的ip地址pi节点高度是:" + numube);
      })
      .catch((err) => {
        console.log(err);
        alert("你输入ip地址无法查询pi节点高度,请检查端口以及ip地址");
      });

    console.log(this.state.username);
  };
  //打开新的网站

  //通过uuid查询节点在线率时间
  windOepn = () => {
    alert(
      "请开梯子,然后输入正确的uuid 防止查询出错,如果没有时间,请检查uuid号或者过几天"
    );
    const w = window.open( this.state.http1 + this.state.username);
    //二次跳转
    //w.location.href = this.state.http1 + this.state.username;
  };
  //查询公网ip地址地方
  changipque = () => {
    const w = window.open("http://www.ip138.com");
  };
  //查询31409 蓝奏下载
  changlzque = () => {
    const w = window.open("http://www.dayuan0307.top:31409");
  };
  //网盘下载
  changwpque = () => {
    const w = window.open("http://www.dayuan0307.top:31408");
  };
  render() {
    return (
      <div>
        <center>
          <h3>自己架设pi节点查询 </h3>
        </center>
        <br></br>
       
        <center>
          {" "}
          <button onClick={this.changipque}>公网ip地址查询</button>
        </center>
        <br></br>
        <center>
          {" "}
          请输入你要查询的ip地址 :{" "}
          <input ref="ip" onChange={this.inputip}></input>
          <button onClick={this.getInput}>查询IP区块高度</button>
        </center>
        <br></br>
        <center>
          请输入你要查询的uuid :{" "}
          <input ref="username" onChange={this.inputChange}></input>
          <button onClick={this.windOepn}>查询节点时间</button>
        </center>
        
        <center>
          {" "}
          <button onClick={this.changlzque}>跳转官网</button>&nbsp;&nbsp;
          <button onClick={this.changwpque}>文件下载</button>
        </center>
        <br></br>
        
       
      </div>
    );
  }
}

export default App;
